<template>
  <div>
    <div style="margin-bottom: 10px;">历史服务系数</div>
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="search()">
      <el-form-item label="日期和时间范围：">
        <el-date-picker
          @change="vildTime"
          v-model="value3"
          type="month"
          value-format="yyyy-MM-dd"
          placeholder="选择月">
        </el-date-picker>
        至
        <el-date-picker
          @change="vildTime"
          v-model="value4"
          type="month"
          value-format="yyyy-MM-dd"
          placeholder="选择月">
        </el-date-picker>
        <el-button @click="search">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;"
    >
      <el-table-column prop="realizeMonth" header-align="center" align="center" label="月份"></el-table-column>
      <el-table-column prop="ratio" header-align="center" align="center" label="服务系数"></el-table-column>
      <el-table-column prop="ratioDesc" header-align="center" align="center" label="备注"></el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <div style="display: flex;justify-content: center;margin: 20px;"><el-button type="primary" @click="goBack">返回</el-button></div>
  </div>
</template>

<script>
  export default {
    name: 'moneyBaseWaitList',
    data() {
      return {
        dataListLoading: false,
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataForm: {},
        value3: '',
        value4: ''
      }
    },
    props: ['id'],
    mounted () {
      this.init()
    },
    methods: {
      search(){
        this.pageIndex = 1;
        this.init();
      },
      init () {
        this.dataListLoading = true
        let obj = {
          page: this.pageIndex,
          limit: this.pageSize,
          userId: this.id
        }
        if (this.value3) {
          obj.startDate = this.value3
        }
        if (this.value4) {
          obj.endDate = this.value4
        }
        this.$http({
          url: this.$http.adornUrl(`/account/saleAccount/historyRatio/list`),
          method: "get",
          params: this.$http.adornParams(obj)
        }).then(({ data }) => {
          this.dataListLoading = false
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
        })
      },
      vildTime () {
        if (new Date(this.value4).getTime() < new Date(this.value3).getTime()) {
          this.value4 = ''
          this.value3 = ''
          this.$message({
            showClose: true,
            message: '结束时间必须大于开始时间',
            type: 'warning'
          });
        }
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val;
        this.pageIndex = 1;
        this.init();
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val;
        this.init();
      },
      goBack () {
        this.$emit('goback')
      }
    }
  }
</script>

<style scoped>

</style>
